package com.smart.ZC.Data;

import java.io.DataInputStream;
import java.io.IOException;

import com.smart.ZC.CGame;
import com.smart.ZC.Tools.Tools;

public class gameLeveldata {

	private int[] ced_levelOffset_1;
	public static short[][] ced_nDrawPos_1;
	public static short[][][][] ced_npcItem_1;

	public gameLeveldata() {

	}

	public gameLeveldata(int type, int level) {
		String levelbin_buf, globalbin_buf;
		levelbin_buf = "levels_" + (level + 1) + ".bin";
		globalbin_buf = "global_" + (level + 1) + ".bin";

		loadGlobeData_1(levelbin_buf, globalbin_buf);
	}

	public void loadGlobeData_1(String levelbin, String globalbin) {
		LoadLevelBin(levelbin);
		LoadGlobalBin(globalbin);
	}

	public void LoadLevelBin(String levelbin) {
		short ced_levelCount;
		try {
			DataInputStream is = new DataInputStream(CGame.context.getAssets()
					.open(levelbin));
			ced_levelCount = Tools.data_readShort(is);
			ced_levelOffset_1 = new int[ced_levelCount + 1];
			for (int i = 0; i < ced_levelCount + 1; i++) {
				ced_levelOffset_1[i] = Tools.data_readInt(is);
			}
			is.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public void LoadGlobalBin(String globalbin) {
		try {
			DataInputStream is = new DataInputStream(CGame.context.getAssets()
					.open(globalbin));
			ced_loadDrawPos_1(is);
			ced_loadNpcItemData_1(is);
			is.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	private void ced_loadNpcItemData_1(DataInputStream is) {
		// TODO Auto-generated method stub
		int i, j;
		short ArrayTwo;
		short ArrayOne = Tools.data_readShort(is);
		ced_nDrawPos_1 = new short[ArrayOne][];
		// ARRAY2_NEW1(cedInfo.ced_nDrawPos_1, short, ArrayOne);
		for (i = 0; i < ArrayOne; i++) {
			ArrayTwo = Tools.data_readShort(is);
			ced_nDrawPos_1 = new short[i][6];
			// ARRAY2_NEW2(cedInfo.ced_nDrawPos_1, short,i, 6);
			for (j = 0; j < 6; j++) {
				if (ArrayTwo != 6) {
					if (j != 5)
						ced_nDrawPos_1[i][j] = Tools.data_readShort(is);
					else
						ced_nDrawPos_1[i][5] = 0;
				} else {
					ced_nDrawPos_1[i][j] = Tools.data_readShort(is);
				}
			}
		}
	}

	private void ced_loadDrawPos_1(DataInputStream is) {
		// TODO Auto-generated method stub
		int i, j, k, m;
		short ArrayOne, ArrayTwo, ArrayThree, ArrayFour;

		ArrayOne = Tools.data_readShort(is);
		ced_npcItem_1 = new short[ArrayOne][][][];
		// ARRAY4_NEW1(cedInfo.ced_npcItem_1, short, ArrayOne);
		for (m = 0; m < ArrayOne; m++) {
			ArrayTwo = Tools.data_readShort(is);
			ced_npcItem_1 = new short[m][ArrayTwo][][];
			// ARRAY4_NEW2(cedInfo.ced_npcItem_1, short, m, ArrayTwo);
			for (i = 0; i < ArrayTwo; i++) {
				ArrayThree = Tools.data_readShort(is);
				ced_npcItem_1 = new short[m][i][ArrayThree][];
				// ARRAY4_NEW3(cedInfo.ced_npcItem_1, short, m, i, ArrayThree);
				for (j = 0; j < ArrayThree; j++) {
					ArrayFour = Tools.data_readShort(is);
					ced_npcItem_1 = new short[m][i][j][ArrayFour];
					// ARRAY4_NEW4(cedInfo.ced_npcItem_1, short, m, i, j,
					// ArrayFour);
					for (k = 0; k < ArrayFour; k++) {
						ced_npcItem_1[m][i][j][k] = Tools.data_readShort(is);
					}
				}
			}
		}
	}
}
